package Methods;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.message.BasicNameValuePair;

import comm.AppInterface;

public class PostDbMethod implements RequestMethods
{
	List <NameValuePair> nvps = new ArrayList <NameValuePair>();
	
	@Override
	public void CreateRequest(String idDevice, String idMeasure, String value) 
	{
	   String action = AppInterface.getPropertyByName("actiondbCrown");
	     
       nvps.add(new BasicNameValuePair(AppInterface.actionName , action));
       nvps.add(new BasicNameValuePair(AppInterface.idDevice   , idDevice));
       nvps.add(new BasicNameValuePair(AppInterface.idMeasure  , idMeasure));
       nvps.add(new BasicNameValuePair(AppInterface.value      , value));
	}


	@Override
	public HttpRequestBase GetRequestBase() 
	{
		HttpPost httpPost = new HttpPost(AppInterface.FormedCallRequest());
		try {
			   httpPost.setEntity(new UrlEncodedFormEntity(nvps));
		    } 
		catch (UnsupportedEncodingException e) 
		    {
			  e.printStackTrace();
		    }
		
		return httpPost;
	}


	@Override
	public String getDescMethod() 
	{
		return "POST";
	}

}
